<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!-- public quote -->
<%@include file="/jsp/comm_css_include.jsp"%>
<link rel="stylesheet" type="text/css" href="${basePath}/css/zTreeStyle/zTreeStyle/zTreeStyle.css">
<!doctype html>
<html>
<head>
<style type="text/css">
li{list-style: none;}

</style>
</head>
<body class="gray-bg">
	<input type="hidden" id="editId"/>
	<div class="container creditbody">
		<div class="iboxtitle">
		 	<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;风控条件修改申请</span>
        </div>
        <div class="buttonfixed">
	       	<button type="button" id="save_button" class="btn dpbtn_blue" onclick="saveCarAction();">保存</button>
	       	<button type="button" id="commit_button" class="btn dpbtn_blue" onclick="commitAction();">提交</button>
	    </div>
	    <%@include file="/jsp/comm_yw_info_include.jsp"%>
        <div class="ibox-content ibox-con">
        	<div class="business-man">项目详情(原)</div>
           	<div class="padding-nono">
		        <table cellpadding="0" cellspacing="0" border="0" class="buyinfor-table">
					<tr>	
						<td align="right">
							<label class="control-label np">加装GPS：</label>
						</td>
						<td>
							<input class="form-control" type="number" readonly="readonly" id="addGpsOld" placeholder="加装GPS" name="addGpsOld" />
						</td>
						
						<td align="right">
							<label class="control-label np">征信押金：</label>
						</td>
						<td>
							<input class="form-control" type="number" id="addGepositOld" readonly="readonly" placeholder="征信押金" name="addGepositOld" />
						</td>
					</tr>
					<tr>		
						<td align="right">
							<label class="control-label np">收费变通：</label>
						</td>
						<td>
							<input class="form-control" type="text" id="flexibleChargeOld" readonly="readonly" placeholder="收费变通" name="flexibleChargeOld" maxlength="64"/>
						</td>
						<td align="right">
							<label class="control-label np">延迟垫款</label>
							<img class="curpo" title="垫款在银行放款后" src="${basePath}/img/ask.png">
						</td>
						<td>
							<select id="isSpecialOrderOld" class="form-control" disabled="disabled">
								<option value="0">否</option>
								<option value="1">是</option>
							</select>
						</td>
					</tr>
				</table>	
			</div>
			<form class="form-horizontal buyinfor-form" id="commentForm">
				<div class="business-manwife">项目详情(新)</div>
	           	<div class="padding-nono">
			        <table cellpadding="0" cellspacing="0" border="0" class="buyinfor-table">
						<tr>	
							<td align="right">
								<label class="control-label np">加装GPS：</label>
							</td>
							<td>
								<input class="form-control" type="number"  id="addGpsNew" placeholder="加装GPS" name="addGpsNew" />
							</td>
							
							<td align="right">
								<label class="control-label np">征信押金：</label>
							</td>
							<td>
								<input class="form-control" type="number" id="addGepositNew" placeholder="征信押金" name="addGepositNew" />
							</td>
						</tr>
						<tr>		
							<td align="right">
								<label class="control-label np">收费变通：</label>
							</td>
							<td>
								<input class="form-control" type="text" id="flexibleChargeNew" placeholder="收费变通" name="flexibleChargeNew" maxlength="64"/>
							</td>
							<td align="right">
								<label class="control-label np">延迟垫款</label>
								<img class="curpo" title="垫款在银行放款后" src="${basePath}/img/ask.png">
							</td>
							<td>
								<select id="isSpecialOrderNew" class="form-control" required="required">
									<option value="">请选择</option>
									<option value="0">否</option>
									<option value="1">是</option>
								</select>
							</td>
						</tr>
						<tr>
		        			<td align="right" valign="top">
								<label class="control-label np">备注信息：</label>
							</td>
							<td colspan="5">
								<textarea id="remarks" name="remarks" required="required" placeholder="备注信息(必填)" class="form-control" ></textarea>
							</td>
		        		</tr>
					</table>	
				</div>
				<!-- 当前经办人 -->
	    		<div class="business-manwife">经办信息</div>
				<div class="padding-nono">
					<table cellpadding="0" cellspacing="0" border="0"
						class="buyinfor-table">
						<tr>
							<td align="right"><label class="control-label np">经办人：</label>
							</td>
							<td><input class="form-control" type="text" id="operate" name="" readonly="readonly" value="${current_user_key.uname}" />
							</td>
							<td align="right"><label class="control-label np">经办时间：</label>
							</td>
							<td><input id="operateTime" name="operateTime" class="form-control"  placeholder="经办时间" readonly="readonly"/></td>
						</tr>
					</table>
				</div>
			</form>
		</div>
	</div>	
	
	<!-- public quote -->
    <%@include file="/jsp/comm_js_include.jsp"%>
    <script type="text/javascript" src="${basePath}/js/plugins/layer/laydate/laydate.js"></script>
    <!-- validate js -->
	<script type="text/javascript" src="${basePath}/js/fksh/validate.js" charset="utf-8"></script>
    <!--
    	时间：2017-04-06
    	描述：js
    -->
    <script type="text/javascript">
	    jQuery(function($) {  
	    	
	    	$("#commentForm").validate({
	            //重写showErrors
	            showErrors: function (errorMap, errorList) {
	                $.each(errorList, function (i, v) {
	                    layer.tips(v.message, v.element, { time: 1500 });
	                    return false;
	                });  
	            },
	            /* 失去焦点时验证 */
	            onfocusout: function(element) { $(element).valid(); },
	            /*  键盘抬起不验证 */
	            onkeyup:false,
	        }); 
	    	getFkAuditCondtion();
	    	setTimeout(function(){
	    		getData();
      	  },500)
	    	geData();
	    	
	    });
	    var flag=true;
		var getFkAuditCondtion=function(){
			var data={};
			data.busiId= $.getUrlData("busiId");
			$.dpAjax({
	    		  url:'${basePath}/FkAuditConditionEditController/list',
		          data: data,
		          success: function (datas) {
		        	var result = datas.result.rows;
		        	if(result.length>0){
		        		for(var i=0;i<result.length;i++){
		        			if(result[i].auditEditStatus==200){
		        				flag=true;
		        			}else{
		        				$("#editId").val(result[i].replaceId);
		        				flag=false;
		        				break;
		        			}
		        		}
		        	}
		          }
		      });
		}
	    var getData=function(){
	    	var busiStatus = $.getUrlData("busiStatus");
	    	if(busiStatus == "9000" || flag){
    		     $("#addGpsNew").val("");
			 	 $("#isSpecialOrderNew").val("");
			 	 $("#flexibleChargeNew").val("");
			 	 $("#addGepositNew").val("");
				 $("#remarks").val("");
				 $("#operateTime").val(laydate.now());
				 return;
	    	}
	    	var data={};
 	 		data.busiId=$.getUrlData("busiId");
 	 		data.type_extras='Audit';
 	 		data.editId=$("#editId").val();
 	 		$.dpAjax({
	    		  url:'${basePath}/FkAuditConditionEditSubController/list',
		          data: data,
		          success: function (datas) {
		        	  var result = datas.result.rows;
		        	  if(result && result !=""){
// 			        	  $("#editId").val(result[0].editId);
			        	  for(var i in result){
			        		  var codeExtras = result[i].codeExtras;
			        		  var valueExtrasOld = result[i].valueExtrasOld;
			        		  var valueExtrasNew = result[i].valueExtrasNew;
			        		  if(codeExtras == "AddGps"){
			        			  $("#addGpsNew").val((valueExtrasNew && valueExtrasNew !="null") ? parseInt(valueExtrasNew) : '');
			        		  }else if(codeExtras == "IsSpecialOrder"){
			        			  $("#isSpecialOrderNew").val(valueExtrasNew);
			        		  }else if(codeExtras == "FlexibleCharge"){
			        			  $("#flexibleChargeNew").val((valueExtrasNew && valueExtrasNew !="null") ? valueExtrasNew : '0');
			        		  }else if(codeExtras == "AddGeposit"){
			        			  $("#addGepositNew").val((valueExtrasNew && valueExtrasNew !="null") ? valueExtrasNew : '0');
			        		  }
			        		  $("#remarks").val(result[i].remarks);
			        		  $("#operateTime").val(formateIntegerDate(result[i].created));
			        	  }
		        	  }else{
		        		  $("#operateTime").val(laydate.now());
		        	  }
		          }
		      });
	    }
	    
	    var geData = function(){
	    	var data={};
 	 		data.busiId=$.getUrlData("busiId");
 	 		data.type_extras='Audit';
	    	$.dpAjax({
	    		  show:false,
	    		  url:'${basePath}/YwBusinessExtrasController/list',
		          data: data,
		          success: function (datas) {
		        	  var result = datas.result.rows;
		        	  if(result && result !=""){
			        	  for(var i in result){
			        		  var codeExtras = result[i].codeExtras;
			        		  var valueExtrasOld = result[i].valueExtras;
			        		  if(codeExtras == "AddGps"){
			        			  $("#addGpsOld").val((valueExtrasOld && valueExtrasOld !="null") ? parseInt(valueExtrasOld) : '0');
			        		  }else if(codeExtras == "FlexibleCharge"){
			        			  $("#flexibleChargeOld").val((valueExtrasOld && valueExtrasOld !="null") ? valueExtrasOld : '0');
			        		  }else if(codeExtras == "AddGeposit"){
			        			  $("#addGepositOld").val((valueExtrasOld && valueExtrasOld !="null") ? valueExtrasOld : '0');
			        		  }else if(codeExtras == "IsSpecialOrder"){
		        				  $("#isSpecialOrderOld").val(valueExtrasOld);
		        			  }
			        	  }
		        	  }
		          }
		      });
	    }
		
	    //保存
	    var saveCarAction = function(){
	    	var busiId = $.getUrlData("busiId");
	    	var cusId = $.getUrlData("cusId");
	    	var editId = $("#editId").val();
	    	var data = {};
	    	
	    	data.busiId = busiId;
	    	data.cusId = cusId;
	    	data.addGpsNew = $("#addGpsNew").val();
	    	data.addGepositNew = $("#addGepositNew").val();
	    	data.flexibleChargeNew = $("#flexibleChargeNew").val();
	    	data.isSpecialOrderNew = $("#isSpecialOrderNew").val();
	    	data.remarks = $("#remarks").val();
	    	
	    	var url="${basePath}/FkAuditConditionEditSubController/insert";
	    	if(!flag){
		    	if(editId && editId != ""){
		    		data.editId = editId;
		    		url="${basePath}/FkAuditConditionEditSubController/update";
		    	}
	    	}
	    	$.dpAjax({
		          url:url,
		          data: data,
		          success: function (datas) {
		        	  $("#editId").val(datas.result);
		        	  layer.msg("执行成功！",{icon:6});
		          }
		      });
	    } 
	    
	    //提交
	    var commitAction = function(){
	    	var validstatus = $("#commentForm").valid();
		    if(!validstatus){
		    	layer.msg("有验证未通过，请仔细检查！",{icon:5});
		    	return;
		    }
	    	var data = {};
	    	data.addGpsNew = $("#addGpsNew").val();
	    	data.addGepositNew = $("#addGepositNew").val();
	    	data.flexibleChargeNew = $("#flexibleChargeNew").val();
	    	data.isSpecialOrderNew = $("#isSpecialOrderNew").val();
	    	data.remarks = $("#remarks").val();
	    	data.editId =  $("#editId").val();
	    	data.busiId = $.getUrlData("busiId");
	    	data.cusId = $.getUrlData("cusId");
	    	$.dpAjax({
		          url:'${basePath}/FkAuditConditionEditSubController/commit',
		          data: data,
		          success: function (datas) {
		        	  layer.msg("执行成功！",{icon:6});
		        	  setTimeout(function(){
		        		  location.href='${basePath}/web/system/yw/fkEditApplyShList.jsp';
		        	  },3000)
		          }
		      });
	    } 
	    
    </script>
</body>
</html>
